﻿#region Using

using System;
using System.Timers;

using Common.Base;

using CommunicationLibrary;
using CommunicationLibrary.TransportData;

#endregion

namespace TestClient
{
    public class Client : IClient
    {
        private readonly Timer timer = new Timer(2000);

        private int i = 0;

        public void GamePaused()
        {
            Console.WriteLine("Game paused!");
        }

        public void GameResumed()
        {
            Console.WriteLine("Game resumed!");
        }

        public void GameStarted()
        {
            Console.WriteLine("Game started!");
            this.timer.Elapsed += this.TimerOnElapsed;
            this.timer.Start();
        }

        public void PlayerLost(Identifiable looser)
        {
            Console.WriteLine(looser.Identifier + " has lost!");
        }

        public void HasWon()
        {
            Console.WriteLine("Me win!");
        }

        public void UpdateGameState(GameState gameState)
        {
            i++;
        }

        public void GameReady(GameState startingState, int identifier)
        {
            Console.WriteLine("Opponent Found! I'm " + identifier);
        }

        private void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            decimal count = this.i;
            this.i = 0;

            Console.WriteLine("Received {0} packets per second", Math.Floor(count / 2));
        }
    }
}